package com.msg.controller;

import com.msg.util.EmailUtil;
import com.msg.service.EmailService;
import com.msg.service.SampleService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;

/**
 * @author lxx
 */
@RequestMapping
@RestController
@RequiredArgsConstructor
public class TestController {


    private final EmailService service;

    private final SampleService sampleService;

    @GetMapping("/email")
    public String email(){

        boolean message =service.sendSimpleMail("2353481215@qq.com","测试主题","1024");
        return message?"发送成功":"发送失败";
    }

    @GetMapping("/emailHtml")
    public String emailHtml(){

        boolean message =service.sendHtmlMail("2353481215@qq.com","html主题", new EmailUtil().buildContent("123456","测试"));
        return message?"发送成功":"发送失败";
    }

    @GetMapping("/emailFile")
    public String emailFile(){
        File file = new File("src/main/resources/static/mailtemplate.ftl");
        boolean message =service.sendAttachmentsMail("2353481215@qq.com","文件主题", "文件内容",file);
        return message?"发送成功":"发送失败";
    }


    @GetMapping("/sample")
    public String sample(){

        boolean message = sampleService.sendSms("18377128612", "{code:123456}", "SMS_154950909","阿里云短信测试");
        return message?"发送成功":"发送失败";
    }


    @GetMapping("/sendBatchSms")
    public String sendBatchSms(){

        boolean message = sampleService.sendBatchSms("[\"18377128612\",\"18377128612\"]", "[{\"code\":\"123456\"},{\"code\":\"78910\"}]", "SMS_175465034","[\"阿里云短信测试\",\"阿里云短信测试\"]");
        return message?"发送成功":"发送失败";
    }
}
